package learn_concurrent._9;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class T4 {
	static final Logger logger = LoggerFactory.getLogger(T4.class);

	static int number = 0;
	static boolean ready = false;

	public static void main(String[] args) throws InterruptedException {
		for (int i = 0; i < 1000; i++) {
			I_Result r = new I_Result();
			new Thread(() -> f2()).start();
			new Thread(() -> f1(r)).start();
			
			Thread.sleep(100);
			if(r.r1 == 0) {
				System.out.println(r.r1);
			}
			
		}

	}

	private static void f1(I_Result r) {
		if (ready) {
			r.r1 = number + number;
		} else {
			r.r1 = 1;
		}
	}

	private static void f2() {
		number = 2;
		ready = true;
	}

	static class I_Result {
		public int r1;
	}
}
